﻿
namespace Catalog.API.Products.GetProductsByCategory
{
    //由于使用来了路由参数，这里不需要定义请求dto
    public record GetProductsByCategoryRequest(string CategoryName);
    public record GetProductsByCategoryResponse(IEnumerable<Product> Products);
    public class GetProductsByCategoryEndpoint : ICarterModule
    {
        public void AddRoutes(IEndpointRouteBuilder app)
        {
            app.MapGet("products/category/{CategoryName}", async (string
                CategoryName, ISender sender) =>
            {
                var result=await sender.Send(new GetProductsByCategoryQuery(CategoryName));
                var response=result.Adapt<GetProductsByCategoryResponse>();
                return Results.Ok(response.Products);

            }).WithName("GetProductByCategory")
        .Produces<GetProductsByCategoryResponse>(StatusCodes.Status200OK)
        .ProducesProblem(StatusCodes.Status400BadRequest)
        .WithSummary("Get Product By Category")
        .WithDescription("Get Product By Category");
        }
    }
}
